package com.hxd.otc.module.home.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.base.BaseRecyclerPresenter;
import com.hxd.otc.module.home.adapter.MessageAdapter;
import com.hxd.otc.module.home.contract.MessageContract;
import com.hxd.otc.module.home.model.MessageModel;
import com.hxd.otc.module.my.bean.BaseListBean;
import com.hxd.otc.module.my.bean.MessageBean;
import com.hxd.otc.module.order.bean.AllOrderBean;
import com.hxd.otc.module.order.model.AllOrderModel;
import com.hxd.otc.net.BaseObserver;

/**
 * Created by lzy on 2019/1/17 0017.
 * description ${消息Presenter}
 */
public class MessagePresenter extends BaseRecyclerPresenter<MessageContract.IView, MessageAdapter, MessageBean> implements MessageContract.IPresenter {

    private final MessageModel mMessageModel;
    private final AllOrderModel mAllOrderModel;

    public MessagePresenter(MessageContract.IView iView) {
        super(iView);
        mMessageModel = MessageModel.getInstance();
        mAllOrderModel = AllOrderModel.getInstance();
    }

    @Override
    public void loadData(final boolean isRefresh) {
        mMessageModel.getMessageList(mPageIndex, getPageSize(), new BaseObserver<BaseListBean<MessageBean>>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull BaseListBean<MessageBean> messageBeanBaseListBean) {
                onLoadDataSuccess(isRefresh, messageBeanBaseListBean.getList());
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                onLoadDataFail(isRefresh, errMessage);
            }
        }, mView.<BaseBean<BaseListBean<MessageBean>>>bindAutoDispose());
    }

    @Override
    public void requestDealOrderDetail(String orderId) {

        mAllOrderModel.getOrderDetailData(new BaseObserver<AllOrderBean.DataBean>() {
            @Override
            public void onNext(String title, AllOrderBean.DataBean bean) {
                if (bean != null)
                    mView.requestDealOrderDetailSuccess(bean);
            }

            @Override
            public void onError(int errType, String errMessage) {
                mView.showToast(errMessage);
            }

        }, mView.<BaseBean<AllOrderBean.DataBean>>bindAutoDispose(), orderId);

    }


}
